// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function AttackSlash()
{
	//攻击刚开始
	if(sprite_index != sPlayerAttackSlash)
	{
		// 初始化正确的动画
		sprite_index = sPlayerAttackSlash;
		localFrame = 0;
		image_index = 0;
		
		//清除 hit list（攻击列表）
		if(!ds_exists(hitByAttack, ds_type_list))
		{
			hitByAttack = ds_list_create();
		}
		ds_list_clear(hitByAttack);
	}
	
	CalcAttack(sPlayerAttackSlashHB);
	
	//更新精灵图
	PlayerAnimateSprite();
	if(animationEnd)
	{
		state = PlayerStateFree;
		animationEnd = false;
	}
	
}
///////////////////////////////////////////
function AttackSpin()
{

}
//////////////////////////////////////////
function CalcAttack(_mask)
{
	mask_index = _mask;
	var hitByAttackNow = ds_list_create();
	var hits = instance_place_list(x , y, pEntity, hitByAttackNow, false);
	if(hits > 0)
	{
		for (var i = 0;i < hits; i++ )
		{
			//如果这个实例没有没攻击过 那么就攻击
			var hitID = hitByAttackNow[| i]; // ds_list_find_value(hitByAttackNow, i)
			if(ds_list_find_index(hitByAttack, hitID) == -1)
			{
				ds_list_add(hitByAttack, hitID);
				with(hitID)
				{
					if(object_is_ancestor(object_index,pEnemy))
					{
						HurtEnemy(id, 5, other.id, 10);
					}else if(entityHitScript != -1) script_execute(entityHitScript);
					
					
				}//with
			}//if(ds_list_find_index(hitByAttack, hitID) == -1)
			
		}//for
	}//if(hits > 0)
	
	ds_list_destroy(hitByAttackNow);
	mask_index = sPlayer;
}
/////////////////
function HurtEnemy(_enemy, _damage, _source, _knockback)
{
	with(_enemy)
	{
		if(state != ENEMYSTATE.DIE)
		{
			enemyHP -= _damage;
			flash = 1;
			
			//掉血还是死亡
			if(enemyHP <= 0)
			{
				state = ENEMYSTATE.DIE;
			}
			else
			{
				if(state != ENEMYSTATE.HURT) statePrevious = state;
				state = ENEMYSTATE.HURT;
			}
			image_index = 0;
			if(_knockback != 0)
			{
				var _knockDirection = point_direction(x, y, (_source).x,(_source).y);
				xTo = x - lengthdir_x(_knockback, _knockDirection);
				yTo = y - lengthdir_y(_knockback, _knockDirection);
			}
			SlimeHurt();
		}
	}
	
}
